import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;


public class ReadProteinSeq {
	private static final String ProfileFileName = null;
	private boolean FileBegin=false;
	//private boolean ProfileBegin=false;
	//private File ProteinFile=null;
	//private BufferedReader reader=null;
	public File ProteinFile = null;
	public FileReader freader = null;
	public LineNumberReader lnreader = null;
	String ProteinFileName;
	String BufferLine;
	boolean Flag_SeqNo=false;
	public  ReadProteinSeq(String Name){
		FileBegin=false;
		ProteinFileName=Name;
		ProteinFile=null;
		freader=null;
		lnreader=null;	
		Flag_SeqNo=false;
		//ProfileBegin=false;
	}
	public  ReadProteinSeq(){
		
	}
	public void OpenProteinSeqFile(){
		try {
			ProteinFile =new File (ProteinFileName);
			freader = new FileReader(ProteinFile);
		    lnreader = new LineNumberReader(freader);

	   }
		catch (FileNotFoundException NoFile) {
			NoFile.printStackTrace();
		}  
	}
	public int FileToProteinSeq(ProteinSeq Sequence) throws IOException{
		String line=new String();
		if(FileBegin==false){// Read the first line of the file
				while((line=lnreader.readLine() )!= null){
					if(line.contains(">sp")){
						BufferLine=line;
						FileBegin=true;
						Flag_SeqNo=true;
						return 0;
					}
				}//End of While Loop
		}
		else{
			if(Flag_SeqNo==true){
				Sequence.ClearSequence();
				Sequence.PutProteinSeq(BufferLine);
				Flag_SeqNo=false;
			}
			while((line=lnreader.readLine())!=null){
				if(line.contains(">sp")){
					BufferLine=line;
					Flag_SeqNo=true;
					break;
				}
				else{
					Sequence.PutProteinSeq(line);
				}
				
			}
		}
		if(line==null){
			return 2;
		}
		else{
			return 1;
		}
	}
	public int MapToProteinSeq(ProteinSeq Sequence, String line) throws IOException{
		if(FileBegin==false){// Read the first line of the file
				while(line!= null){
					if(line.contains(">sp")){
						BufferLine=line;
						FileBegin=true;
						Flag_SeqNo=true;
						return 0;
					}
				}//End of While Loop
		}
		else{
			if(Flag_SeqNo==true){
				Sequence.ClearSequence();
				Sequence.PutProteinSeq(BufferLine);
				Flag_SeqNo=false;
				Sequence.PutProteinSeq(line);
				return 0;
			}
				if(line.contains(">sp")){
					BufferLine=line;
					Flag_SeqNo=true;
					return 1;
				}
				else{
					Sequence.PutProteinSeq(line);
				}
				
			}
		if(line==null){
			return 2;
		}
		return 0;
	}


}
		

